﻿using System;
using RpcHelper;
using SqlExecHelper;
using SqlExecHelper.SetColumn;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.DAL
{
        internal class ServiceVerRouteDAL : SqlBasicClass
        {
                public ServiceVerRouteDAL () : base ("ServiceVerRoute")
                {

                }
                public Guid Add (ServiceVerRoute add)
                {
                        add.Id = Tools.NewGuid ();
                        base.Insert (add);
                        return add.Id;
                }
                public void Adds (ServiceVerRoute[] adds,long verId)
                {
                        adds.ForEach (a => {
                                a.Id = Tools.NewGuid ();
                                a.VerId = verId;
                        });
                        base.Insert (adds);
                }
                public ServiceVerRoute Get(Guid id)
                {
                        return base.GetRow<Guid, ServiceVerRoute> ("Id", id);
                }
                public ServiceVerRoute[] GetRoutes (long verId)
                {
                        return base.Get<long, ServiceVerRoute> ("VerId", verId);
                }
                public void Set (Guid id, VerRouteSet set)
                {
                        if (!base.Update (set, "Id", id))
                        {
                                throw new ErrorException ("rpc.route.set.fail");
                        }
                }
                public void Delete (Guid id)
                {
                        if (!base.Drop ("Id", id))
                        {
                                throw new ErrorException ("rpc.route.drop.fail");
                        }
                }
                internal void SetIsEnable (Guid id, bool isEnable)
                {
                        if (!base.Update (new ISqlSetColumn[] {
                                new SqlSetColumn("IsEnable", System.Data.SqlDbType.Bit){ Value=isEnable}
                        }, "Id", id))
                        {
                                throw new ErrorException ("rpc.route.set.fail");
                        }
                }
                public void Clear (long verId)
                {
                        base.Drop ("VerId", verId);
                }
        }
}
